﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Radiation___IM.Commands
{
    public class Invisible : ICommand
    {
        private readonly string m_commandkey = "invisible";

        public Invisible()
        {
        }

        public string commandKey()
        {
            return m_commandkey;
        }

        public void execute(string[] command_parts, Client client)
        {
            switchInvisibility(client);
        }

        public string requiredPermission()
        {
            return null;
        }

        public static void switchInvisibility(Client client)
        {
            if (!client.Invisible)
            {
                foreach (Radiation___IM.Channel chan in client.Channels.Values)
                    chan.dispatchMessageAPI(chan.Name + ";" + client.Nickname, Radiation.Common.Communication.APIMethods.CLIENT_REMOVE_USER);
                client.Invisible = true;
                MessageExecution.sendData(client, "You're now invisible.");
            }
            else
            {
                foreach (Radiation___IM.Channel chan in client.Channels.Values)
                    chan.dispatchMessageAPI(chan.Name + ";" + client.Nickname, Radiation.Common.Communication.APIMethods.CLIENT_ADD_USER);
                client.Invisible = false;
                MessageExecution.sendData(client, "You're now visible again.");
            }
        }
    }
       
}
